package cn.iocoder.yudao.module.xiaoBizHandler.dal.mysql.tbFile;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.xiaoBizHandler.controller.admin.tbFile.vo.XTbFileExportReqVO;
import cn.iocoder.yudao.module.xiaoBizHandler.controller.admin.tbFile.vo.XTbFilePageReqVO;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.tbFile.XTbFileDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 文件 Mapper
 *
 * @author XiaoSiyuan
 */
@Mapper
public interface XTbFileMapper extends BaseMapperX<XTbFileDO> {

    default PageResult<XTbFileDO> selectPage(XTbFilePageReqVO reqVO) {
        List<String> folderIds = new ArrayList<>();
        if (null != reqVO.getFolderId()) {
            folderIds = Arrays.asList(reqVO.getFolderId().split(","));
        }
        return selectPage(reqVO, new LambdaQueryWrapperX<XTbFileDO>()
                .inIfPresent(XTbFileDO::getFolderId, folderIds)
                .likeIfPresent(XTbFileDO::getFileName, reqVO.getFileName())
                .eqIfPresent(XTbFileDO::getFileSuffix, reqVO.getFileSuffix())
                .eqIfPresent(XTbFileDO::getFileOwnerId, reqVO.getFileOwnerId())
                .eqIfPresent(XTbFileDO::getRemark, reqVO.getRemark())
                .eqIfPresent(XTbFileDO::getFileSize, reqVO.getFileSize())
                .likeIfPresent(XTbFileDO::getFileType, reqVO.getFileType())
                .eqIfPresent(XTbFileDO::getFilePath, reqVO.getFilePath())
                .betweenIfPresent(XTbFileDO::getFileCreateTime, reqVO.getBeginFileCreateTime(), reqVO.getEndFileCreateTime())
                .betweenIfPresent(XTbFileDO::getFileLastTime, reqVO.getBeginFileLastTime(), reqVO.getEndFileLastTime())
                .eqIfPresent(XTbFileDO::getFileCheckSum, reqVO.getFileCheckSum())
                .orderByDesc(XTbFileDO::getSort)
                .orderByDesc(XTbFileDO::getId));
    }

    default List<XTbFileDO> selectList(XTbFileExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<XTbFileDO>()
                .eqIfPresent(XTbFileDO::getFolderId, reqVO.getFolderId())
                .likeIfPresent(XTbFileDO::getFileName, reqVO.getFileName())
                .eqIfPresent(XTbFileDO::getFileSuffix, reqVO.getFileSuffix())
                .eqIfPresent(XTbFileDO::getFileOwnerId, reqVO.getFileOwnerId())
                .eqIfPresent(XTbFileDO::getRemark, reqVO.getRemark())
                .eqIfPresent(XTbFileDO::getFileSize, reqVO.getFileSize())
                .likeIfPresent(XTbFileDO::getFileType, reqVO.getFileType())
                .eqIfPresent(XTbFileDO::getFilePath, reqVO.getFilePath())
                .betweenIfPresent(XTbFileDO::getFileCreateTime, reqVO.getBeginFileCreateTime(), reqVO.getEndFileCreateTime())
                .betweenIfPresent(XTbFileDO::getFileLastTime, reqVO.getBeginFileLastTime(), reqVO.getEndFileLastTime())
                .eqIfPresent(XTbFileDO::getFileCheckSum, reqVO.getFileCheckSum())
                .orderByDesc(XTbFileDO::getSort)
                .orderByDesc(XTbFileDO::getId));
    }

}
